﻿/********************************************************************************
 * Developed by Phil Tyler (http://www.laidbackcoder.co.uk)
 * 
 * Cryptosolic is Licensed under the GNU Lesser General Public License (LGPL)
 * http://cryptosolic.codeplex.com/license
 * *****************************************************************************/
using System;
using NUnit.Framework;
using System.Collections.Generic;
using System.Text;
using Cryptosolic.Utilities;

namespace Cryptosolic.Security.Tests
{
    [TestFixture]
    public class RandomNumberGeneratorTests
    {
        [Test]
        public void RNG_GenerateRandomData_OutputBytesNotRepeatable()
        {
            List<byte[]> RandomDataSamples = new List<byte[]>();

            for(int i=0; i<100; i++)
            {
                RandomDataSamples.Add(RandomNumberGenerator.GenerateRandomData(256));
            }

            CollectionAssert.AllItemsAreUnique(RandomDataSamples);
        }

        [Test]
        public void RNG_GenerateRandomData_OutputHexNotRepeatable()
        {
            List<string> RandomDataSamples = new List<string>();

            for (int i = 0; i < 100; i++)
            {
            	RandomDataSamples.Add(DataConverter.BytesToHex(RandomNumberGenerator.GenerateRandomData(256)));
            }

            CollectionAssert.AllItemsAreUnique(RandomDataSamples);
        }

        [Test]
        public void RNG_GenerateRandomData_OutputBytesExpectedSize()
        {
            int ExpectedSize = 512;

            byte[] data = RandomNumberGenerator.GenerateRandomData(ExpectedSize);
            
            int ActualSize = data.Length;

            Assert.AreEqual(ExpectedSize, ActualSize);
        }

        [Test]
        public void RNG_GenerateRandomData_OutputHexExpectedSize()
        {
            int InitialSize = 512;

            StringBuilder sb = new StringBuilder();

            string randomData = DataConverter.BytesToHex(RandomNumberGenerator.GenerateRandomData(InitialSize));

            int ActualSize = randomData.Length;

            //Initial Size x 2 as each Hex value consists of two alphanumeric characters.
            Assert.AreEqual(InitialSize * 2, ActualSize);
        }
    }
}
